import React from 'react'
import { Switch, Route } from 'react-router-dom'

/**
 * 用于渲染路由组件
 * @param {*} routes
 * @returns
 */
const renderRoutes = routes => routes ? (
  <Switch>
    {
      routes.map(route => (
        <Route
          key={route.path}
          path={route.path}
          exact={route.exact}
          render={props => (
            route.render
              ? route.render({...props, route})
              : <route.component {...props} route={route} />
          )}
        />
      ))
    }
  </Switch>
) : null

export default renderRoutes
